package view.equipe;

import java.awt.GridLayout;
import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;

import rmi.RemoteObserver;
import server.models.equipe.Equipe;
import server.models.equipe.IEquipe;
import server.models.partie.IPartie;

public class EquipeContainerView extends JPanel implements RemoteObserver {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String nomClient = null;

	public EquipeContainerView(IPartie partie, String nomClient) throws RemoteException, NotBoundException, AlreadyBoundException {
		super();
		this.nomClient = nomClient;
		this.setLayout(new GridLayout(3,2));
		partie.addObserver(this);
		for (IEquipe equipe : partie.getListeEquipes()) {
			ajouterEquipeView(equipe);
		}

		this.repaint();
	}

	public void ajouterEquipeView(IEquipe equipe) throws RemoteException, NotBoundException, AlreadyBoundException {
		this.add(new EquipeView(equipe, this.nomClient));
		this.validate();
	}

	@Override
	public void update(Object partie, Object equipe) {

//		try {
//			for (IEquipe equipePartie : ((IPartie)partie).getListeEquipes()) {
//				this.add(new EquipeView(equipePartie));
//
//			}
//		} catch (RemoteException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (NotBoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (AlreadyBoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		this.repaint();
	}
}
